﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace Client
{
    public class DelegateCommand<T> : ICommand
        where T : class
    {
        private Action<T> command;
        private Predicate<T> canExecute;

        public DelegateCommand(Action<T> execute)
        {
            this.command = execute;
        }

        public DelegateCommand(Action<T> execute, Predicate<T> canExecute)
            : this(execute)
        {
            this.canExecute = canExecute;
        }

        public bool CanExecute(object parameter)
        {
            return canExecute == null || canExecute((T)parameter);
        }

        public void Execute(object parameter)
        {
            command((T)parameter);
        }

        public event EventHandler CanExecuteChanged;
    }
}